/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.capex.javaee.sockets;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 *
 * @author Acer
 */
public class TcpClient {

    public static void main(String[] args) {
        try {
            String message = "Hello, I'm Here\n";
            String response;
            
            Socket client = new Socket("localhost", 6789);

            BufferedReader inFromServer = new BufferedReader(new InputStreamReader(client.getInputStream()));
            DataOutputStream outToServer = new DataOutputStream(client.getOutputStream());

            outToServer.writeBytes(message);

            response = inFromServer.readLine();

            System.out.println("From Server: "+response);
            client.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
